import store from '@/store';

export const showValue = (value) => {
  if (!value && value !== 0) {
    return '--'
  }
  return value
}

// 把一个文件数组，拆出图片和视频数组
export function splitFilesToImageVideo (files) {
  const images = []
  const videos = []
  const imageTypes = ['jpeg', 'jpg', 'png', 'gif','webp']
  const videoTypes = ['mp4', 'avi', 'mov', 'wmv']
  
  files?.forEach((file) => {
    const extension = file.fileName.split('.').pop().toLowerCase()
    if (imageTypes.includes(extension)) {
      images.push(file)
    } else if (videoTypes.includes(extension)) {
      videos.push(file)
    }
  })
  
  return {
    images,
    videos,
  }
}

// 设置角标
export const setTabBarBadge = () => {
  const num = uni.getStorageSync("MESSAGE_NUMBERS") || store.getters.GET_MESSAGE_NUMBERS;
  console.log('num', num);
  if (num === '0') {
    uni.removeTabBarBadge({ index: 2 })
  } else {
    uni.setTabBarBadge({
      index: 2,
      text: num
    })
  }
};